﻿using Helper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StudentStatistics
{
    /// <summary>
    /// EveryQuestionTimeControl.xaml 的交互逻辑
    /// </summary>
    public partial class EveryQuestionTimeControl : UserControl
    {

        public double NewWidth
        {
            get { return (double)GetValue(NewWidthProperty); }
            set { SetValue(WidthProperty, value); }
        }
        public static readonly DependencyProperty NewWidthProperty =
            DependencyProperty.Register("NewWidth", typeof(double), typeof(EveryQuestionTimeControl), new PropertyMetadata(1800d));

        public ObservableCollection<StudentData> Items
        {
            get { return (ObservableCollection<StudentData>)GetValue(ItemsProperty); }
            set { SetValue(ItemsProperty, value); }
        }
        public static readonly DependencyProperty ItemsProperty =
            DependencyProperty.Register("Items", typeof(ObservableCollection<StudentData>), typeof(EveryQuestionTimeControl), new PropertyMetadata(new ObservableCollection<StudentData>()));

        public ObservableCollection<StudentData> orderItem = new ObservableCollection<StudentData>();

        //  private bool orderByRate = false;
        /// <summary>
        /// 当前页数
        /// </summary>
        private int CurrentPage = 0;
        /// <summary>
        /// 每页显示多少数据
        /// </summary>
        public int PageCount = 30;

        AminationHelpers amination = new AminationHelpers();

        public EveryQuestionTimeControl()
        {
            InitializeComponent();

            this.Items = orderItem;

            //var mousesliderhelper = new MouseSliderHelper(this) { IsVerctor = true };
            //mousesliderhelper.MouseAction += mousesliderhelper_MouseAction;
            this.Loaded += EveryQuestionTimeControl_Loaded;
        }


        void EveryQuestionTimeControl_Loaded(object sender, RoutedEventArgs e)
        {
            InitPresentView();
            amination.SetAmination(listview, new PropertyPath(Control.HeightProperty), 0d, 690d);
            BringToTop();
            // new AnimationHelpers().SetAnimation("NewControl", this, NewControl);
        }

        void mousesliderhelper_MouseAction(object sender, MouseType e)
        {
            switch (e.Type)
            {
                case ActionType.Up:
                    {
                        InitFrontView();
                        //e.MouseArgs.Handled = true;
                        break;
                    }

                case ActionType.Down:
                    {
                        InitNextView();
                        //e.MouseArgs.Handled = true;
                        break;
                    }

                default: break;
            }
        }
        public void InitPresentView()
        {
            this.Items = this.orderItem;
            //this.Items = new ObservableCollection<StudentData>(orderItem.Skip(CurrentPage * PageCount).Take(PageCount).ToList());
        }

        private void InitNextView()
        {
            if ((CurrentPage + 1) * PageCount <= orderItem.Count)
            {
                CurrentPage++;
            }
            this.Items = this.orderItem;
            // this.Items = new ObservableCollection<StudentData>(orderItem.Skip(CurrentPage * PageCount).Take(PageCount).ToList());
        }

        private void InitFrontView()
        {
            CurrentPage--;
            if (CurrentPage < 0)
            {
                CurrentPage = 0;
            }
            this.Items = this.orderItem;
            //this.Items = new ObservableCollection<StudentData>(orderItem.Skip(CurrentPage * PageCount).Take(PageCount).ToList());
        }

        public void BringToTop()
        {
            listview.ScrollIntoView(this.Items.FirstOrDefault());
        }
    }
}
